{template header}
<script type="text/javascript">
 usernameok=1;
 repasswdok=1;
 emailok=1;
 codeok=1;
function check_username(){
	var username=$.trim($('#username').val());
	var length=bytes(username);
 	if( length <3 || length >15 ){
		$('#usernametip').html("<font color='red'>用户名请使用3到15个字符！</font>");
		usernameok=0;
	}else{
		$.post("{SITE_URL}index.php?c=user&a=ajaxusername",{username: username}, function(flag){
			if(-1==flag){
				$('#usernametip').html("<font color='red'>此用户名已经存在！</font>");
				usernameok=0;
			}else if(-2==flag){
				$('#usernametip').html("<font color='red'>用户名含有禁用字符！</font>");
				usernameok=0;
			}else{
				$('#usernametip').html("<font color='green'>OK</font>");
			}
		});
	}
}

function check_passwd(){
	var passwd=$('#password').val();
	if( bytes(passwd) <6|| bytes(passwd)>16){
		$('#passwordtip').html("<font color='red'>密码最少6个字符，最长不得超过16个字符密码！</font>");
	}else{
		$('#passwordtip').html("<font color='green'>OK</font>");
	}
}

function check_repasswd(){
	var repassword=$('#repassword').val();
	if( bytes(repassword) <6|| bytes(repassword)>16){
		$('#repasswordtip').html("<font color='red'>密码最少6个字符，最长不得超过16个字符密码！</font>");
		repasswdok=0;
	}else{
		if($('#password').val()==$('#repassword').val()){
			$('#repasswordtip').html("<font color='green'>OK</font>");
		}else{
			$('#repasswordtip').html("<font color='red'>两次密码输入不一致！</font>");
			repasswdok=0;
		}
	}
}

function check_email(){
	var email=$.trim($('#email').val());
	if (!email.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){
        $('#emailtip').html("<font color='red'>邮件格式不正确!</font>");
		emailok=0;
    }else{
		$.post("{SITE_URL}index.php?c=user&a=ajaxemail",{email: email}, function(flag){
			if(-1==flag){
				$('#emailtip').html("<font color='red'>此邮件地址已经注册！</font>");
				emailok=0;
			}else if(-2==flag){
				$('#emailtip').html("<font color='red'>邮件地址被禁止注册！</font>");
				emailok=0;
			}else{
				$('#emailtip').html("<font color='green'>OK</font>");
			}
		});
    }
}

function check_code(){
	var code=$.trim($('#code').val());
	$.post("{SITE_URL}index.php?user/ajaxcode",{code: code}, function(flag){
		if(1==flag){
		   	$('#codetip').html("<font color='green'>OK</font>");
		 }else{
			$('#codetip').html("<font color='red'>验证码不匹配！</font>");
			codeok=0;
		 }
	});
}

function docheck(){
<!--{if $setting['code_register']}-->
	return (usernameok && repasswdok && emailok && codeok);
<!--{else}-->
	return (usernameok && repasswdok && emailok );
<!--{/if}-->
}


</script>
<div id="content">
	<div  id="loginForm">
		<div class="block">
		<div class="title"><h3>注册新用户</h3></div>

		<div class="tips">
			<ul>
		      <li>如果您已经注册，请点此“<a href="index.php?c=user&a=login">登录</a>”。</li>
		      <li>忘记密码了？请点击“<a href="index.php?c=user&a=getpass">找回密码</a>”。</li>
		  </ul>
		</div>
			
		<form name="registform"   action="index.php?c=user&a=register" method="post" onsubmit="return docheck();">
			<div class="formItem">
			  <ul>
					<li>
			          	用&nbsp;户&nbsp;名：<input type="text" size="42"  maxlength="18" class="txt" id="username" name="username" onblur="check_username()">
			          	<span id="usernametip">用户名可以使用英文字母，也可以使用中文名字</span>
					</li>
			      	
			      	<li>
						登录密码：<input type="password" size="42" maxlength="16" class="txt" id="password" name="password"  onblur="check_passwd()">
						<span id="passwordtip">密码长度为6～16位，区分字母大小写。</span>
			      	</li>

			      	<li>
						密码确认：<input type="password" size="42" maxlength="16" class="txt" id="repassword" name="repassword"  onblur="check_repasswd()">
						<span id="repasswordtip">同密码设置一样。</span>
			      	</li>
			      	
					<li>
			          	电子邮箱：<input type="text" size="42" class="txt" maxlength="40" id="email" name="email" onblur="check_email()" >
			          	<span id="emailtip"></span>
					</li>

					<!--{if $setting['code_register']}-->
						<li>
							验&nbsp;证&nbsp;码：<input type="text" size="10"  maxlength="4" id="code" name="code" onblur="check_code()" />
				
							<img id="verifycode" onclick="javascript:updatecode();" src="index.php?c=user&a=code"/>&nbsp;
							<span id="codetip"><a href="javascript:updatecode();">看不清，换一个</a></span>
						</li>
					<!--{/if}-->
				  
				  <li class="btns">
					<input name="forward" type="hidden" id="forward" value="{$forward}">
				  	<input type="submit" value="好了，提交" name="submit" class="btn">
			      </li>
			  </ul>
			</div>
		</form>

		</div>
	</div>
</div>
{template footer}